<link href="css/buttons.dataTables.min.css" rel="stylesheet">
<link href="css/select.dataTables.min.css" rel="stylesheet">

<div class="row">
    <div id="breadcrumb" class="col-md-12">
        <ol class="breadcrumb">
            <li><a href="#">投诉报修</a></li>
            <li><a href="#">投诉</a></li>
        </ol>
    </div>
</div>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <div class="box-name">
                </div>
                <div class="box-icons">
                    <a class="expand-link">
                        <i class="fa fa-expand"></i>
                    </a>
                </div>
                <div class="no-move"></div>
            </div>
            <div class="box-content no-padding">
                <table class="table table-bordered table-striped table-hover table-heading table-datatable"
                       id="complainListTable">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>主题</th>
                        <th>用户电话</th>
                        <th>投诉时间</th>
                        <th>状态</th>
                        <th>评分</th>
                        <th>处理人</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <!-- Start: list_row -->
                    <!-- End: list_row -->
                    </tbody>
                    <tfoot>
                    <tr>
                        <th>序号</th>
                        <th>主题</th>
                        <th>用户电话</th>
                        <th>投诉时间</th>
                        <th>状态</th>
                        <th>评分</th>
                        <th>处理人</th>
                        <th>操作</th>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" role="dialog" id="formModel">
    <div class="modal-dialog" role="document" style="width: 900px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="gridSystemModalLabel">投诉处理</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-12" id="complainInfo">
                            <ul class="list-group">
                                <li class="list-group-item">主题: <span id="title"></span></li>
                                <li class="list-group-item">投诉时间: <span id="time"></span></li>
                                <li class="list-group-item">描述: <span id="description"></span></li>
                                <li class="list-group-item">详情: <p id="detail"></p></li>
                                <li class="list-group-item">图片: <img
                                        src="http://7xlqn0.com1.z0.glb.clouddn.com/banner.jpg"
                                        style="width: 800px; opacity: 1;"></li>
                                <li class="list-group-item">状态: <span id="status"></span></li>
                                <li class="list-group-item">评分: <span id="remark"></span></li>
                                <!--<li class="list-group-item">回复:-->
                                    <!--<textarea name="" id="" cols="59" rows="5">我们已收到您的投诉请求,正在处理中,处理过程中有任何不满,请及时反馈你的意见,谢谢</textarea>-->
                                <!--</li>-->
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <!--<button type="button" class="btn btn-primary" id="submitEstate">处理</button>-->
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script type="text/javascript">
    var editTable;//全局的datatable变量

    //删除数据
    $('#complainListTable tbody').on( 'click', 'button#delRowBtn', function () {
        var data = editTable.row($(this).parents('tr') ).data();
        var comfirm=confirm("确定删除?")
        if(comfirm)
        {
            $.ajax({
                type: "get",
                async: true,
                url: urlConfig.deleteComplain+data.id,
                dataType: "json",
                success: function (result) {
                    if (result.status) {
                        alert("删除成功!");
                        editTable.ajax.reload( null, false );
                    }
                    else
                    {
                        alert(result.errorMsg.description);
                    }
                },
                error: function () {
                    alert("服务器连接失败,请重试!");
                }
            });
        }
    });


    $('#complainListTable tbody').on( 'click', 'button#deailRowBtn', function () {
        var data = editTable.row($(this).parents('tr') ).data();
        console.log(data);

        $("#complainInfo #title").text(data.title);
        $("#complainInfo #time").text(data.time);
        $("#complainInfo #description").text(data.description);
        $("#complainInfo #detail").text(data.content);
        $("#complainInfo #status").text(data.status);
        $("#complainInfo #remark").text(data.remark);
        $("#formModel").modal("show");//弹出框show
        $("#formModel").find('.modal-title').text("投诉详情");

    });


    //初始化表格数据
    function initDataTable(){
        editTable=$('#complainListTable').DataTable({
            "processing":true,
            "serverSide": true,
            "ajax":{
                "url": urlConfig.complainList,
                "dataSrc": "jsonString"
            },
            "columnDefs": [{
                "targets": 0,
                "data":null,
                "orderable": false,
                "searchable": false,
                "createdCell": function (nTd, sData, oData, iRow, iCol) {
                    var startnum=this.api().page()*(this.api().page.info().length);
                    $(nTd).html(iRow+1+startnum);
                }
            },{
                "targets": 1,
                "data": "title",
                "visible": true,
                "orderable": false,
                "searchable": false
            },{
                "targets": 2,
                "data": "phone",
                "orderable": false,
                "searchable": false

            },{
                "targets": 3,
                "data": "time",
                "orderable": false,
                "searchable": false,
                "render": function ( data, type, row ) {
                    return formatDate(data,"yyyy-MM-dd");
                }
            },{
                "targets": 4,
                "data": "status",
                "orderable": false,
                "searchable": false,
                "render": function ( data, type, row ) {
                    if(data==0)
                        return "<font color='red'>待处理</font>";
                    else if(data==1)
                        return "<font color='#4b0082'>待用户评价</font>";
                    else if(data==2)
                        return "<font color='green'>处理完成</font>";
                    else
                        return "--";
                }
            },{
                "targets": 5,
                "data": "remark",
                "orderable": false,
                "searchable": false
            },{
                "targets": 6,//删除
                "data": 'consoleUserEntity.name',
                "orderable": false,
                "searchable": false,
                "defaultContent":"--"
            },{
                "targets": 7,//删除
                "data": null,
                "orderable": false,
                "searchable": false,
                "defaultContent":
                        "<button id='deailRowBtn' class='btn btn-primary' type='button'>详情</button>&ensp;"+
                        "<button id='delRowBtn' class='btn btn-primary' type='button'>删除</button>"
            }
            ],
            "aaSorting": [[ 1, "asc" ]],
            "autoWidth":false,
            "sDom":
                    "<'box-content'<'col-sm-6'f><'col-sm-6 text-right'l><'clearfix'>>tr<'box-content'<'col-sm-6'i><'col-sm-6 text-right'p><'clearfix'>>",
            "language": {
                "emptyTable":     "没有相关数据",
                "info": "显示 _START_ 到 _END_ 条, 共 _TOTAL_ 条记录",
                "infoEmpty":      "没有相关数据",
                "infoFiltered":   "(筛选自 _MAX_ 条记录)",
                "infoPostFix":    "",
                "thousands":      ",",
                "lengthMenu":     "每页显示 _MENU_ 条",
                "loadingRecords": "加载中",
                "processing":     "数据处理中",
                "search":         "搜索:",
                "zeroRecords":    "没有找到匹配数据",
                "paginate": {
                    "first":      "首页",
                    "last":       "末页",
                    "next":       "下一页",
                    "previous":   "上一页"
                },
                "aria": {
                    "sortAscending":  ":正序",
                    "sortDescending": ":倒序"
                }
            }
        });

    }
    $(document).ready(function() {
        $('#payTime').datepicker({setDate: new Date(),dateFormat:"yy-mm-dd",
            showButtonPanel:true,
            closeText:"关闭",
            yearSuffix: '年',
            currentText:'今天',
            showMonthAfterYear:true,
            monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
            dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
            dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'],
            dayNamesMin: ['日','一','二','三','四','五','六']
        });
        LoadDataTablesScripts(initDataTable);
    });
</script>
